package com.store.practice.controller;

import com.store.practice.common.api.CommonPage;
import com.store.practice.common.api.CommonResult;
import com.store.practice.model.BgAppointmentOrder;
import com.store.practice.model.BgMember;
import com.store.practice.service.MemberManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "MemberManageController",description = "会员管理")
@RequestMapping("/storeMember")
@RestController
public class MemberManageController {
    @Autowired
    private MemberManageService memberManageService;

    @ApiOperation("展示会员列表")
    @GetMapping("/list")
    public CommonResult list(Integer storeId){
        List<BgMember> list = memberManageService.list(storeId);
        if (list==null){
            return CommonResult.failed();
        }
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation("展示会员预约记录")
    @GetMapping("/getOrder")
    public CommonResult getOrder(Integer mbrId){
        List<BgAppointmentOrder> list = memberManageService.getOrder(mbrId);
        if (list==null){
            return CommonResult.failed();
        }
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation("操作预约记录状态")
    @PostMapping("/updateStatus")
    public CommonResult updateStatus(Integer id,Integer status){
        int i = memberManageService.updateStatus(id, status);
        if (i>0){
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }
}
